﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using Peekaboo2008.dao;

namespace Peekaboo2008.view
{
    public partial class FormBaoCaoHangTonTheoTungNhomHang : Form
    {        
        public FormBaoCaoHangTonTheoTungNhomHang()
        {
            InitializeComponent();
            dateTimePicker1.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            LoadChiNhanh();
            LoadNhomHang();
        }


        /**/
        // Lay du lieu tu table ChiNhanh bang store sp_ChiNhanh_GetALL do vao cbbChiNhanh
        /**/

        public void LoadChiNhanh()
        {
            cbbChiNhanh.DataSource = ChiNhanhDAO.GopTenVaDiaChi();
            cbbChiNhanh.DisplayMember = "Chi_nhanh";
            cbbChiNhanh.ValueMember = "ID";
        }


        /**/
        // Lay du lieu tu table NhomHang bang store sp_NhomHang_GetALL do vao cbbNhomHang
        /**/

        public void LoadNhomHang()
        {
            cbbNhomHang.DataSource = NhomHangDAO.getAll();
            cbbNhomHang.DisplayMember = "Ten";
            cbbNhomHang.ValueMember = "ID";
        }

        private void btnChapNhan_Click(object sender, EventArgs e)
        {
            timer.Interval = 250;
            timer.Start();
        }

        private void btnKetThuc_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            this.progressBar.Value += 10;
            if (this.progressBar.Value == this.progressBar.Maximum)
            {
                timer.Stop();
                String chiNhanh = Convert.ToString(cbbChiNhanh.SelectedValue.ToString());
                String nhomHang = Convert.ToString(cbbNhomHang.SelectedValue.ToString());
                String tuNgay = dateTimePicker1.Value.Month.ToString() + "/" + dateTimePicker1.Value.Day.ToString() + "/" + dateTimePicker1.Value.Year.ToString();
                String denNgay = dateTimePicker2.Value.Month.ToString() + "/" + dateTimePicker2.Value.Day.ToString() + "/" + dateTimePicker2.Value.Year.ToString();
                FormReportViewerHangTonTheoTungNhomHang frmBaoCao = new FormReportViewerHangTonTheoTungNhomHang(chiNhanh, nhomHang, tuNgay, denNgay);
                if (frmBaoCao.IsDisposed)
                {
                    MessageBox.Show("Không có dữ liệu để báo cáo.");
                }
                else
                {
                    frmBaoCao.ShowDialog();
                }
                this.progressBar.Value = 0;
            }
        }
    }
}
